package com.safe;


import com.connect.nio.FastEcho;
import com.dto.cnc.CncDTO;
import io.netty.channel.ChannelHandlerAdapter;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.util.concurrent.DefaultThreadFactory;
import lombok.extern.slf4j.Slf4j;

@Slf4j(topic = "检查通信情况实现类")
public class CheckCNCImpl extends ChannelHandlerAdapter implements CheckCNC {


    public boolean checkCNCOnline() throws InterruptedException {
        String cncServerHost = CncDTO.getCnc_ip();
        int cncServerPort = Integer.parseInt(CncDTO.getCnc_port());
        EventLoopGroup group = new NioEventLoopGroup(1,new DefaultThreadFactory("check-online-1",false));
        return new FastEcho().doFastEcho(group,cncServerHost,cncServerPort);
    }


    @Override
    public boolean checkCNCOnline(String cncServerHost,int cncServerPort) throws InterruptedException {
        EventLoopGroup group = new NioEventLoopGroup(1,new DefaultThreadFactory("check-online-2",false));
        return new FastEcho().doFastEcho(group,cncServerHost,cncServerPort);
    }

}
